cmake_minimum_required(VERSION 3.21.2)

execute_process(COMMAND gcc -dumpfullversion -dumpversion OUTPUT_VARIABLE GCC_VERSION)
#message(STATUS "gcc version = ${GCC_VERSION}")

if (GCC_VERSION LESS "4.9.3")
    message(FATAL_ERROR "gcc version need greater than 4.9.3")
endif()

project(index_model_trainer)
execute_process(COMMAND git log -1 --pretty=format:%h . OUTPUT_VARIABLE version)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g -O2 -lrt -Wall")

include_directories(../../include)
include_directories(../../include/comm)
include_directories(../../include/config_parser)
include_directories(../../include/faiss_adapter)

aux_source_directory(./                             SRC_FILES_FUNC)
aux_source_directory(../../src/config_parser        SRC_FILES_CONFIG_PARSER)
aux_source_directory(../../src/faiss_adapter        SRC_FILES_FAISS_ADAPTER)

set(SRC_FILES)
list(APPEND SRC_FILES   ${SRC_FILES_FUNC}
                        ${SRC_FILES_CONFIG_PARSER}
                        ${SRC_FILES_FAISS_ADAPTER})

link_directories(
    ${PROJECT_SOURCE_DIR}/../../../../comm
    ${PROJECT_SOURCE_DIR}/../../../../3rdlib/jsoncpp/lib
    ${PROJECT_SOURCE_DIR}/../../../../3rdlib/faiss/lib
)

add_executable(index_model_trainer  ${SRC_FILES})

target_include_directories(index_model_trainer PUBLIC
    ${PROJECT_SOURCE_DIR}/../../../../comm
    ${PROJECT_SOURCE_DIR}/../../../../3rdlib/jsoncpp/include
    ${PROJECT_SOURCE_DIR}/../../../../3rdlib/faiss
    ${PROJECT_SOURCE_DIR}/../../../../3rdlib
)

add_definitions(-DACTIVE_GIT_VERSION="${version}" -DMAIN)

target_link_libraries(index_model_trainer PRIVATE faiss jsoncpp common ssl pthread dl)
set_target_properties(index_model_trainer PROPERTIES RUNTIME_OUTPUT_DIRECTORY "../../bin")
